<html>

<!-- Mirrored from introcomputing.org/table-3-exercises.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 24 Jan 2019 10:59:38 GMT -->
<head>
<title>Table 3 Exercises</title>
<link rel=stylesheet href=style.css type="text/css">

</head>
<body>
<script type="text/javascript" src="cs101.js"></script>
<script type="text/javascript" src="cs101-table.js"></script>
<script type="text/javascript" src="cs101-simulation.js"></script>

<!-- njp
<div id=warning-output></div>
-->

<h1>Table 3 Exercises</h1>

<p>



<p>
For these exercises, we use and (&amp;&amp;), or (||) to combine multiple tests in an if-test. The baby fields are "name", "rank", "gender", "year".

<p>
1. Write code to print all the rows where the name starts with "X" or the name starts with "Y". Suggestion: when you have code running, look carefully at the output. Does the output look reasonable? For this problem for example, do you see a mix of names starting with either "X" or "Y"? It's nice if you can quickly check the correctness of your code right when you run it.

<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="table3-ex1" rows=10 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
table = new SimpleTable("baby-2010.csv");
for (row: table) {
  // your code here
  
}</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("table3-ex1")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='table3-ex1-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>



<p>
2. Write code to print all the rows where the name starts with "B" and the name ends with "a". As above, glance at the output to check that it looks right.

<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="table3-ex2" rows=10 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
table = new SimpleTable("baby-2010.csv");
for (row: table) {
  // your code here
  
}</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("table3-ex2")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='table3-ex2-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>


<p>
3. Write code to print all the rows where the name ends with "i" and the gender is "boy". Reminder of "boy" test: row.getField("gender") == "boy"

<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="table3-ex3" rows=10 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
table = new SimpleTable("baby-2010.csv");
for (row: table) {
  // your code here
  
}</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("table3-ex3")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='table3-ex3-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>


<p>
4. Write code to print all the rows where the rank is &lt;= 10 and the gender is "boy" (i.e. the top 10 boy names).

<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="table3-ex4" rows=10 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
table = new SimpleTable("baby-2010.csv");
for (row: table) {
  // your code here
  
}</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("table3-ex4")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='table3-ex4-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>



</body>

<!-- Mirrored from introcomputing.org/table-3-exercises.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 24 Jan 2019 10:59:38 GMT -->
</html>

